﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Yz.Base;
using Yz.Core.Tools;

namespace Yz.ApiService.Filters
{
    [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = true)]
    public class ExceptionAttribute : ExceptionFilterAttribute
    {
        public override void OnException(ExceptionContext context)
        {
            Exception exception = context.Exception;
            JsonResult result = new JsonResult(new VmReturn() { Suc = false, Msg = "出现未知错误" })
            {
                StatusCode = 200
            };
            YzNLog.Fatal(exception);
            context.Result = result;
        }
    }
}
